package MyPassage.model;

import javafx.beans.binding.NumberBinding;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;

public class Product {
    private StringProperty name;
    private IntegerProperty countBegin;
    private IntegerProperty additionalCount1;
    private IntegerProperty additionalCount2;
    private IntegerProperty additionalCount3;
    private IntegerProperty additionalCount4;
    private IntegerProperty price;
    private IntegerProperty countNow;
    private IntegerProperty countSold;
    private IntegerProperty totalSum;
    private IntegerProperty tableNumber;

    //  Constructor for new products
    public Product(String name, int table) {
        this(name, 0, 0, 0, 0, 0, 0, 0, table);
    }

    //  Constructor for products from DB
    public Product(String name,
                   int countBegin,
                   int additionalCount1,
                   int additionalCount2,
                   int additionalCount3,
                   int additionalCount4,
                   int price,
                   int countNow,
                   int tableNumber) {
        this.name = new SimpleStringProperty(name);
        this.countBegin = new SimpleIntegerProperty(countBegin);
        this.additionalCount1 = new SimpleIntegerProperty(additionalCount1);
        this.additionalCount2 = new SimpleIntegerProperty(additionalCount2);
        this.additionalCount3 = new SimpleIntegerProperty(additionalCount3);
        this.additionalCount4 = new SimpleIntegerProperty(additionalCount4);
        this.price = new SimpleIntegerProperty(price);
        this.countNow = new SimpleIntegerProperty(countNow);
        this.tableNumber = new SimpleIntegerProperty(tableNumber);

        NumberBinding nbCountAll =
                this.countBegin
                        .add(this.additionalCount1)
                        .add(this.additionalCount2)
                        .add(this.additionalCount3)
                        .add(this.additionalCount4);
        this.countSold = new SimpleIntegerProperty();
        this.countSold.bind(nbCountAll.subtract(this.countNow));
        this.totalSum = new SimpleIntegerProperty();
        this.totalSum.bind(this.countNow.multiply(this.price));
    }

    //  Getters and setters
    public String getName() {
        return name.get();
    }
    public StringProperty nameProperty() {
        return name;
    }
    public void setName(String name) {
        this.name.set(name);
    }

    public int getCountBegin() {
        return countBegin.get();
    }
    public IntegerProperty countBeginProperty() {
        return countBegin;
    }
    public void setCountBegin(int countBegin) {
        this.countBegin.set(countBegin);
    }

    public int getAdditionalCount1() {
        return additionalCount1.get();
    }
    public IntegerProperty additionalCount1Property() {
        return additionalCount1;
    }
    public void setAdditionalCount1(int additionalCount1) {
        this.additionalCount1.set(additionalCount1);
    }

    public int getAdditionalCount2() {
        return additionalCount2.get();
    }
    public IntegerProperty additionalCount2Property() {
        return additionalCount2;
    }
    public void setAdditionalCount2(int additionalCount2) {
        this.additionalCount2.set(additionalCount2);
    }

    public int getAdditionalCount3() {
        return additionalCount3.get();
    }
    public IntegerProperty additionalCount3Property() {
        return additionalCount3;
    }
    public void setAdditionalCount3(int additionalCount3) {
        this.additionalCount3.set(additionalCount3);
    }

    public int getAdditionalCount4() {
        return additionalCount4.get();
    }
    public IntegerProperty additionalCount4Property() {
        return additionalCount4;
    }
    public void setAdditionalCount4(int additionalCount4) {
        this.additionalCount4.set(additionalCount4);
    }

    public int getPrice() {
        return price.get();
    }
    public IntegerProperty priceProperty() {
        return price;
    }
    public void setPrice(int price) {
        this.price.set(price);
    }

    public int getCountNow() {
        return countNow.get();
    }
    public IntegerProperty countNowProperty() {
        return countNow;
    }
    public void setCountNow(int countNow) {
        this.countNow.set(countNow);
    }

    public int getCountSold() {
        return countSold.get();
    }
    public IntegerProperty countSoldProperty() {
        return countSold;
    }
    public void setCountSold(int countSold) {
        this.countSold.set(countSold);
    }

    public int getTotalSum() {
        return totalSum.get();
    }
    public IntegerProperty totalSumProperty() {
        return totalSum;
    }
    public void setTotalSum(int totalSum) {
        this.totalSum.set(totalSum);
    }

    public int getTableNumber() {
        return tableNumber.get();
    }
    public IntegerProperty tableNumberProperty() {
        return tableNumber;
    }
    public void setTableNumber(int tableNumber) {
        this.tableNumber.set(tableNumber);
    }
}